package booking.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import booking.misc.Airport;
import booking.misc.DBConnectionData;
import booking.misc.User;

public class FlightBooking extends JFrame implements ActionListener {
	
	Image winter;
	
	static final String EXIT 	 = "signOut";
	static final String BOOKINGS = "myBookings";
	static final String USERS 	 = "users";
	static final String AIRPORTS = "airports";
	static final String FLIGHTS = "flights";
	public static User currentUser;
    
	public FlightBooking() {
		boolean isAdmin = currentUser.getAdmin();
//		System.out.println(currentUser);
        JPanel panel = new JPanel(new BorderLayout());
        setContentPane(panel);
        
        JToolBar toolbar = new JToolBar();
        
        JButton signOut = new JButton("Sign Out");
        signOut.addActionListener(this);
        signOut.setActionCommand(EXIT);
        toolbar.add(signOut);
        
        JButton myBookingsB = new JButton("My bookings");
        myBookingsB.addActionListener(this);
        myBookingsB.setActionCommand(BOOKINGS);
        toolbar.add(myBookingsB);
        
        
        JButton usersB = new JButton("Users");
        usersB.setEnabled(isAdmin);
        usersB.addActionListener(this);
        usersB.setActionCommand(USERS);
        toolbar.add(usersB);
        
        JButton airportsB = new JButton("Airports");
        airportsB.setEnabled(isAdmin);
        airportsB.addActionListener(this);
        airportsB.setActionCommand(AIRPORTS);
        toolbar.add(airportsB);
        
        JButton flightB = new JButton("Flights");
        flightB.setEnabled(isAdmin);
        flightB.addActionListener(this);
        flightB.setActionCommand(FLIGHTS);
        toolbar.add(flightB);
        
        add(toolbar, BorderLayout.PAGE_START);
		
		getContentPane().setBackground(Color.WHITE);
        setTitle("Logged In");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        
        JLabel background=new JLabel(new ImageIcon("images/logo.jpg")); 
        
    	add(background);
    	background.setLayout(new FlowLayout());
        
//        Background contentPane = new Background();
        
	}
	

	public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
            	DBConnectionData.setConnectionData( 
      	       			 "jdbc:mysql://localhost:3306/booking", "root", "root");
            	
                Login frame = new Login(null, true);
                frame.getContentPane().setBackground(Color.BLACK);
                frame.setTitle("Logged In");
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                
                currentUser = frame.getUser();
                FlightBooking ex = new FlightBooking();
   	            ex.setVisible(true);
            }
        });
    }

	@Override
	public void actionPerformed(ActionEvent e) {
		String action = e.getActionCommand();
		switch (action) {
		case EXIT:
			System.exit(0);
			break;
		case USERS:
			UserWindow ud = new UserWindow();
            ud.setVisible(true);
//            Airport airport = ad.getAirport();
//            if (airport != null) {
//                airportModel.addAirport(airport);
//            }
			break;
		case AIRPORTS:
			AirportWindow addAirport = new AirportWindow();
            addAirport.setVisible(true);
			break;
		case FLIGHTS:
			FlightWindow addFlight = new FlightWindow();
	        addFlight.setVisible(true);
			break;
		case BOOKINGS:
			BookingWindow addBooking = new BookingWindow();
	        addBooking.setVisible(true);
			break;
		}
	}
}

